import request from '@/utils/request'
export const loginUser = (data: any) => {
  return request({
    url: '/manage/login',
    method: 'post',
    data
  })
}

export const loginSocialUser = (params: any) => {
  params.grant_type = 'social'
  params.scope = 'server'
  return request({
    url: '/auth/oauth/token',
    method: 'post',
    headers: {
      Authorization: 'Basic cmV2aWV3X2VkbV9zb2NpYWw6bGF6eXBnQDIwMjA='
    },
    params
  })
}

export const bindSocialAccount = (data: any) => {
  return request({
    url: '/admin/user/bind',
    method: 'post',
    data
  })
}

export const createUser = (data: any) =>
  request({
    url: '/admin/user/',
    method: 'post',
    data
  })

export const deleteUser = (id: number) =>
  request({
    url: `/admin/user/${id}`,
    method: 'delete'
  })

export const updateUser = (id: number, data: any) =>
  request({
    url: `/admin/user/${id}`,
    method: 'put',
    data
  })

export const getUser = (id: number) =>
  request({
    url: `/admin/user/${id}`,
    method: 'get'
  })

export const getUserInfo = () =>
  request({
    url: '/userinfo/get',
    method: 'get'
  })

export const getUserList = (params: any) =>
  request({
    url: '/admin/user/users',
    method: 'get',
    params
  })

export const getUserMenuTree = () =>
  request({
    url: '/admin/menu/currentUser/tree',
    method: 'get'
  })
export const getMenuTree = () =>
  request({
    url: '/admin/menu/tree',
    method: 'get'
  })

export const addMenu = (data: any) => {
  return request({
    url: '/admin/menu',
    method: 'post',
    data
  })
}
export const getMenuDetail = (id: any) => {
  return request({
    url: '/admin/menu/' + id,
    method: 'get'
  })
}

export const updateMenu = (data: any) => {
  return request({
    url: '/admin/menu/' + data.id,
    method: 'put',
    data
  })
}

export const deleteMenu = (id: any) => {
  return request({
    url: '/admin/menu/' + id,
    method: 'delete'
  })
}
